'use strict';

angular.module('app')
  .directive('header', function () {
    return {
      templateUrl: 'templates/header.html',
      controller: function ($scope, svcState, svcMain) {
          $scope.loggedIn = false;

          $scope.$on('EVENT.LOGGED_IN', function() {
              $scope.member = svcState.getLoginUser();
              $scope.loggedIn = true;
          });

          $scope.$on('EVENT.LOGGED_OUT', function() {
              $scope.member = '';
              $scope.loggedIn = false;
              svcState.setLoginUser('');
          });

          $scope.logout = function() {
              svcMain.logout().then(function(){
                  svcState.gotoLogin();
              });
          };
      }
    };
  })

  .directive('footer', function () {
    return {
      transclude: false,
      templateUrl: 'templates/footer.html',
      controller: function ($scope, svcState) {
        $scope.copyrightYear = (new Date()).getFullYear();
      }
    };
  })

;